import pandas as pd

df1 = pd.DataFrame(
    [{"r1": 'a', "r2": 1},
     {"r1": "b", "r2": 2},
     {"r1": "c", "r2": 2},
     {"r1": "a", "r2": 3}
     ]
)

df1["r1"].drop_duplicates()


def multi_target_filter():
    # Test1: 如何一列的内容进行多条件过
    print(df1)
    filted_cols = ["a", "b"]
    filted_df = df1.loc[df1.r1.isin(filted_cols)]
    print(filted_df)
    # Test1结论:使用isin函数


def df_to_dict():
    dict1 = df1.to_dict(orient="list")
    print(dict1)


def date_str_sort_test():
    df2 = pd.DataFrame(
        [
            {"date": "2017-05-08", "r1": 'a', "r2": 1},
            {"date": "2018-05-08", "r1": "b", "r2": 2},
            {"date": "2019-05-08", "r1": "c", "r2": 2},
            {"date": "2020-05-08", "r1": "a", "r2": 3}
         ]
    )
    df2.set_index("date", inplace=True)
    df3 = df2.loc["2018-06-01":]
    print(df3)



if __name__=="__main__":
    #multi_target_filter()
    # df_to_dict()
    date_str_sort_test()
